package com.happycat.service.impl;
 
import java.util.List;

import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.happycat.mobile.model.UserMenu;
import com.happycat.mobile.service.UserMenuService;
import com.happycat.mapper.UserMenuMapper;
import com.happycat.SysContants;
import com.happycat.ResponseModel;
import com.happycat.Pagination;
import com.happycat.ResponseHeaderModel;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
/**
 * Module: UserMenu.java
 * 
 * @author liaoyong
 * @since JDK 1.8
 * @version 1.0
 * @date 2020-07-14
 * @Descriptions:
 */
@Service
public class UserMenuServiceImpl extends ServiceImpl<UserMenuMapper, UserMenu> implements UserMenuService {
 		
 	public ResponseModel<UserMenu> selectOne(UserMenu userMenu){
 		Wrapper<UserMenu> queryWrapper = new QueryWrapper<>(userMenu);
		ResponseModel<UserMenu> responseModel = new ResponseModel<>();
		responseModel.setCode(SysContants.SYS_SUCCESS_CODE);
		responseModel.setMessage("查询成功");
		responseModel.setData(getOne(queryWrapper));
		return responseModel;
 	
 	}
	
	public ResponseHeaderModel	add(UserMenu userMenu){
		ResponseHeaderModel responseHeaderModel = new ResponseHeaderModel();
		
		boolean result = save(userMenu);
		if(result) {
			responseHeaderModel.setCode(SysContants.SYS_SUCCESS_CODE);
			responseHeaderModel.setMessage("新增成功");
		}else {
			responseHeaderModel.setCode(SysContants.SYS_FAIL_CODE);
			responseHeaderModel.setMessage("新增失败");
		}
		return responseHeaderModel;
	}
	
	public ResponseHeaderModel	modify(UserMenu userMenu){
			ResponseHeaderModel responseHeaderModel = new ResponseHeaderModel();
		
		boolean result = updateById(userMenu);
		if(result) {
			responseHeaderModel.setCode(SysContants.SYS_SUCCESS_CODE);
			responseHeaderModel.setMessage("修改成功");
		}else {
			responseHeaderModel.setCode(SysContants.SYS_FAIL_CODE);
			responseHeaderModel.setMessage("修改失败");
		}
		return responseHeaderModel;
	}
	
	public ResponseModel<Page<UserMenu>> pageList(Pagination<UserMenu>page){
		ResponseModel<Page<UserMenu>> responseModel = new ResponseModel<>();
		responseModel.setCode(SysContants.SYS_SUCCESS_CODE);
		responseModel.setMessage("查询成功");
		responseModel.setData(page(page,new QueryWrapper<UserMenu>(page.getEntity())));
		return responseModel;
	}
	
	public List<UserMenu> getMenuMappingRoleList(){
		return this.baseMapper.getMenuMappingRoleList();
	}

}
